package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.query.TravelQuery;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 主页控制
 */
@Controller
public class IndexController {
    @Reference
    private ITravelCommendService travelCommendService;
    @Reference
    private IStrategyCommendService strategyCommendService;
    @Reference
    private ITravelService travelService;

    //@RequiredLogin
    @RequestMapping("")
    //访问主页,跳转
    public String index(Model model) {
        //推荐游记5篇
        List<TravelCommend> tcs = travelCommendService.listTop5();
        model.addAttribute("tcs", tcs);
        List<StrategyCommend> scs = strategyCommendService.listTop5();
        model.addAttribute("scs", scs);

        return "/index/index";
    }

    @RequestMapping("/index/travelPage")
    //访问主页,跳转
    public String travelPage(TravelQuery qo, Model model) {
        PageInfo pageInfo = travelService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "/index/travelPageTpl";
    }

}
